﻿using System;
using System.IO;
using System.Xml;
using System.Configuration;
using System.Web;
using SyCODE.Component.DataFactory;
using System.Collections.Specialized;
using SyCODE.Component.Security;
using SyCODE.Component.Cryptography;
using SyCODE.Component;
using System.Text.RegularExpressions;
using System.Web.Security;

/// <summary>
/// SyCODE 的摘要说明
/// </summary>
namespace SyCODE.Blog
{
    public class SetStyleSheet : IHttpHandler
    { 
        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
			Ticket ticket = Ticket.Get(FormsAuthentication.FormsCookieName);
            if (Ticket.Authenticate(ticket))
            {
                string styletext = context.Request.Form["styletext"];
                styletext = Regex.Replace(styletext, "<[^>]*>", "");
                styletext = Regex.Replace(styletext, @"[\s-]*e\s*x\s*p\s*r\s*e\s*s\s*s\s*i\s*o\s*n\s*", "-expression", RegexOptions.IgnoreCase);
                File.WriteAllText(Path.Combine(AppPath.GetUserPhysicalPath(ticket.Name), "style.css"), styletext, context.Request.ContentEncoding);
            }
            else
            {
                Function.ClientAlert(StringResource.GetField("authfaild"));
            }
        }
    }
}